<?php	
$key = Uri::segment(3);
print ("<center><a href='../logout/".$key."'>LOGOUT</a></center>");
?>

<script>
		
	
	( function($) {
	
   $(document).ready(function() {


			  $('#form_birthday').datepicker();
		  
		  });
		 
		 /*EQUIPMENTS*/
		 
		     $(document).ready(function() {

		    //Prepare jTable
			$('#PeopleTableContainer').jtable({
				title: 'Equipments',
				sorting: true,
				paging: true,
				pageSize: 10,
				defaultSorting: 'name ASC',
				actions: {
					listAction: '../search_equipment?session=<?php echo $key; ?>',
					createAction: '../addEquip?session=<?php echo $key; ?>',
					updateAction: '../updateEquip?session=<?php echo $key; ?>',
					deleteAction: '../deleteEquip?session=<?php echo $key; ?>'
				},
				fields: {
					id: {
						create: false,
						edit: false,
						list: false,
						key: true
					},
					equipment_id: {
						title: 'Equipment ID',
						width: '40%',
						create: false,
						edit: false,
						list: false			
						
					},
					name: {
						title: 'Equipment Name',
						width: '20%',
						list: true
					},
					description: {
						title: 'Description',
						width: '30%',
						list: true
					},
					added: {
						title: 'Record date',
						width: '30%',
						type: 'date',
						create: false,
						edit: false,
						list: true
					}
				}
			});
		$('#PeopleTableContainer').jtable('load');
		  });
		  
		     $(document).ready(function() {

			 $("#form_test_").keyup(function(){
			 
		
			if($("#form_test_").length!=0 && $("#form_test_").val() != ''){
			
			$('#PeopleTableContainer').jtable('load',{ name : $(this).val()});
			
			}else{
			
			$('#PeopleTableContainer').jtable('load');
				
				}
			
			
			});
					  });
					  
			
				/*STAFF*/
					  
					     $(document).ready(function() {

		    //Prepare jTable
			$('#userTableContainer').jtable({
				title: 'Users',
				sorting: true,
				paging: true,
				pageSize: 10,
				defaultSorting: "username ASC",
				actions: {
					listAction: '../fetchUser?session=<?php echo $key; ?>',
					createAction: '../addUser?session=<?php echo $key; ?>',
					
					updateAction: '../updateUser?session=<?php echo $key; ?>',
					
					deleteAction: '../deleteAccount?session=<?php echo $key; ?>'
					
				},
				fields: {
				/* custom column - image 
				TestColumn: {
				title: 'Test',
				display: function (data) {
				return '<img src="http://localhost/apicomm.backend/public/assets/css/loading.gif" />';
				}
					},
					*/
				//nested table for the extra info of the user(s).
				
				 Info: {
                    title: '',
                    edit: false,
                    create: false,
                    listClass: 'child-opener-image-column',
                    display: function (data) {
                        //Create an image that will be used to open child table
                        var $img = $('<img class="child-opener-image" src="http://localhost/apicomm.backend/public/assets/css/edit.png" title="Edit " />');
                        //Open child table when user clicks the image
                        $img.click(function () {
                            $('#userTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: data.record.first_name+' '+data.record.last_name+"'s Info",
                                        actions: {
                                            listAction: '../fetchUser?session=<?php echo $key; ?>&queryuser='+data.record.username,
                                        },
                                        fields: {
													password: {
														title: 'Password',
														type: 'password',
														list: false,
														edit: false,
														create: true
													},
													id: {
														title: 'ID',
														//type: 'date',
														create: false,
														edit: false,
														list: false
													},
													gender: {
														title: 'Gender',
														//type: 'date',
													},	
													birthday: {
														title: 'Birthday',
														type: 'date',
													},		
													country: {
														title: 'Country',
														//type: 'date',
													},		
													city: {
														title: 'City',
														//type: 'date',
													},	
													street_address: {
														title: 'Street Address',
														//type: 'date',
													},	
													mobile: {
														title: 'Mobile Number',
														//type: 'date',
													},		
													schedule_days: {
														title: 'Schedule Days',
														//type: 'date',
													},	
													schedule_time: {
														title: 'Schedule Time',
														//type: 'date',
													},	
													role_id: {
														title: 'Role ID',
														//type: 'date',
													},				
													permissions: {
														title: 'Permissions',
													}
                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                        });
                        //Return image to show on the person row
                        return $img;
                    }
                },
				
					username: {
						title: 'Username',
						create: true,
						edit: false,
						list: true,
						key: true
						
					},
					password: {
						title: 'Password',
						type: 'password',
						list: false,
						edit: false,
						create: true
						
					},
					employee_id: {
						title: 'Employee ID',
						width: '10%',
						edit: false,
						create: false,
						list: true
					},
					id: {
						title: 'ID',
						//type: 'date',
						create: false,
						edit: false,
						list: false
					},
					first_name: {
						title: 'First Name',
						//type: 'date',
					},
					last_name: {
						title: 'Last Name',
						//type: 'date',
					},	
					gender: {
						title: 'Gender',
						list: false,
						//type: 'date',
					},	
					birthday: {
						title: 'Birthday',
						list: false,
						type: 'date',
					},		
					country: {
						title: 'Country',
						list: false,
						//type: 'date',
					},		
					city: {
						title: 'City',
						list: false,
						//type: 'date',
					},	
					street_address: {
						title: 'Street Address',
						list: false,
						//type: 'date',
					},	
					mobile: {
						title: 'Mobile Number',
						list: false,
						//type: 'date',
					},		
					schedule_days: {
						title: 'Schedule Days',
						list: false,
						//type: 'date',
					},	
					schedule_time: {
						title: 'Schedule Time',
						list: false,
						//type: 'date',
					},	
					role_id: {
						title: 'Role ID',
						list: false,
						//type: 'date',
					},
					level: {
						title: 'User level',
					},					
					permissions: {
						title: 'Permissions',
						list: false,
						type: 'checkbox',
						values: { 
						'view_records': 'Able to view/search user list', 
						'view_equipments': 'Able to view/search equipment list',
						'administer_records': 'Able to administer users', 
						'administer_equipments': 'Able to administer equipments'
						}
					}
					
				}
			});
		$('#userTableContainer').jtable('load');
		  });
		  
		     $(document).ready(function() {

			 $("#form_test__").keyup(function(){
			 
		
			if($("#form_test__").length!=0 && $("#form_test__").val() != ''){
			
			$('#userTableContainer').jtable('load',{ username : $(this).val()});
			
			}else{
			
			$('#userTableContainer').jtable('load');
				
				}
			
			
			});
					  });		  
					  

} ) ( jQuery );

	</script>

</br>

<ul class="tabs center">

<li><a href="#tabr1">Equipments</a></li>
<li><a href="#tabr2">Users</a></li>


</ul>

<div id="tabr1" class="tab-content">
	<?php 
	echo Form::label('Search','',array('style'=>'position:relative;left:5px;padding:2px 2px 2px 2px;border:1px solid black; border-radius:5px 5px 5px 5px;'));
	echo Form::input('test_','',array('style'=>'position:relative;left:10px')); 
	?>
<div id="PeopleTableContainer" style="width: auto; height: auto; position:relative;"></div>
</div>

<div id="tabr2" class="tab-content">
	<?php 
	echo Form::label('Search','',array('style'=>'position:relative;left:5px;padding:2px 2px 2px 2px;border:1px solid black; border-radius:5px 5px 5px 5px;'));
	echo Form::input('test__','',array('style'=>'position:relative;left:10px')); 
	?>
<div id="userTableContainer" style="width: auto; height: auto; position:relative;"></div>
</div>


			<!--
			echo "<script>
		
			var f1z = new LiveValidation('form__password');	
			f1z.add( Validate.Presence );
			f1z.add( Validate.Length, { minimum: 8, maximum: 32 } );
				
			var f1 = new LiveValidation('form___password');
			f1.add( Validate.Confirmation, { match: 'form__password' } );
			f1.add( Validate.Presence );
			
			var f10 = new LiveValidation('form__username');
			f10.add( Validate.Presence );
			f10.add( Validate.Length, { minimum: 5, maximum: 16 } );
			
			var f20 = new LiveValidation('form_first_name');
			f20.add( Validate.Presence );

			var f21 = new LiveValidation('form_last_name');
			f21.add( Validate.Presence );
			
			var a7 = new LiveValidation('form_birthday');
			a7.add( Validate.Presence );
	
			var a6 = new LiveValidation('form_city');
			a6.add( Validate.Presence );

			var a5 = new LiveValidation('form_street_address');
			a5.add( Validate.Presence );

			var a3 = new LiveValidation('form_mobile');
			a3.add( Validate.Presence );
			a3.add( Validate.Numericality, { onlyInteger: true } );
			a3.add( Validate.Length, { is: 11 } );

			var a2 = new LiveValidation('form_schedule_days');
			a2.add( Validate.Presence );

			var a1 = new LiveValidation('form_schedule_time');
			a1.add( Validate.Presence );


			</script>
			
			-->
		